$(function(){
    var galleryThumbs_wap = new Swiper('.proshow_list_con', {
        spaceBetween: 10,
        slidesPerView: 4,
        freeMode: true,
        watchSlidesVisibility: true,
        watchSlidesProgress: true,
    });
    new Swiper('.proshow_top', {
        spaceBetween: 10,
        navigation: {
            nextEl: '.proshow_list .swiper-button-next',
            prevEl: '.proshow_list .swiper-button-prev',
        },
        thumbs: {
            swiper: galleryThumbs_wap
        }
    });

    var galleryThumbs = new Swiper('.proshow_list_con_pc', {
        direction : 'vertical',
        width: 100,
        // loop: true,
        spaceBetween : 5,
        slidesPerView: 4
    });
    new Swiper('.proshow_top_pc', {
        spaceBetween: 10,
        navigation: {
            nextEl: '.proshow_list_pc .swiper-button-next',
            prevEl: '.proshow_list_pc .swiper-button-prev',
        },
        thumbs: {
            swiper: galleryThumbs
        }
    });

    new Swiper('.banner', {
        loop: true,
        speed: 700,
        autoplay: true,
        navigation: {
            nextEl: '.banner .swiper-button-next',
            prevEl: '.banner .swiper-button-prev',
        },
        on: {
            init: function () {
                var total = this.slides.length - 2;
                $('.total').text('0' + total);
                this.emit('transitionEnd');
            },
            transitionEnd: function () {
                var index = this.realIndex + 1;
                $(".active").text("0" + index);
            }
        },
    })

    $('.mcnc_item').click(function (){
        $('.mcnc_item').attr('class','mcnc_item');
        $(this).attr('class','mcnc_item m_act');
        let sid = $(this).attr('data-sid');
        $('.mb_company_news').hide();
        $('.mb_company_news[data-sid='+sid+']').show();
    })

    $('.toPreview').click(function (){
        let source_src= $(this).attr('src');
        $('#image-preview').attr('src',source_src);
        $('.image-preview').show();
    })
    $('.image-preview').click(function (){
        $(this).hide();
    })

})

function sub_icontact(){
    let username = $('#username').val();
    let email = $('#email').val();
    let tel = $('#tel').val();
    let question = $('#con').val();
    // 获取表单数据
    var formData = {
        username : username,
        email : email,
        tel : tel,
        question : question,
    };

    // 使用AJAX进行POST提交
    $.ajax({
        type: 'POST',
        url: '/index/icontact', // 替换为你的PHP处理脚本的URL
        data: formData,
        dataType: 'json', // 如果你希望从服务器端返回JSON数据，可以设置为json
        encode: true
    })
    .done(function(data){
        sysmsg(data.msg);

    })
    .fail(function(data){
        // 处理提交失败的情况
        sysmsg(data.msg);
    });
}
function sub_pro(){
    let product_id = $('#product_id').val();
    let contact = $('#con').val();
    $.ajax({
        type: 'POST',
        url: '/index/product_mess', // 替换为你的PHP处理脚本的URL
        data: {
            id :product_id,
            contact : contact
        },
        dataType: 'json', // 如果你希望从服务器端返回JSON数据，可以设置为json
        encode: true
    })
        .done(function(data){
            sysmsg(data.msg)

        })
        .fail(function(data){
            // 处理提交失败的情况
            sysmsg(data.msg)
        });
}

function sysmsg(text){
    var htmlToAppend = "<div id='sys-message'>"+text+"</div>";
    $('body').append(htmlToAppend);
    setTimeout(function() {
        // 删除刚才插入的内容
        $('#sys-message').remove();
    }, 2000);
}
